package ru.jexp.rcp.supply.actions;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;

import ru.jexp.rcp.supply.editor.EditorInputBean;

public class ActionNew extends Action
{

	private IWorkbenchWindow window;
	private String idEditor;

	public ActionNew(IWorkbenchWindow window, String nameEditror, String idEditor, ImageDescriptor icon)
	{
		setText(nameEditror);
		setImageDescriptor(icon);
		this.window = window;
		this.idEditor = idEditor;
	}

	@Override
	public void run()
	{
		try
		{
			window.getActivePage().openEditor(new EditorInputBean(getText()), idEditor);
		}
		catch (PartInitException e)
		{
			e.printStackTrace();
		}
	}

	final IWorkbenchWindow getWindow()
	{
		return window;
	}

}
